<template>
  <div class="screenCustomer">
    <div class="mask"></div>
    <div class="screenCustomerContent">
      <div class="screenCustomerTop">
        <p>筛选客户</p>
        <i class="el-icon-close" @click="close"></i>
      </div>
      <div class="screenCustomerBtn">
        <span>客户</span>
        <el-input v-model="customerNo" style="width:60px;margin: 0 10px;height:30px" @blur="customerNoBlur"></el-input>
        <el-select v-model="customerName" style="width:90px;margin-right:10px" @change="e=>{this.customerNo=e}">
          <el-option
            v-for="item in customerList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-button icon="el-icon-zoom-in" type="primary" @click="search">查询</el-button>
        <el-button icon="el-icon-document-checked" @click="preservationCN">保存</el-button>
        <el-button icon="el-icon-delete" @click="Delete">删除</el-button>
        <el-button icon="el-icon-delete" @click="clean">清空</el-button>
      </div>
      <div class="box1">
        <el-table
          height="495"
          :header-cell-style="{padding:0,height:'40px',background:'#f4f4f4'}"
          :cell-style="{padding:0,height:'36px'}"
          :data="clientData"
          ref="clientData">
          <el-table-column
            type="selection"
            width="50">
          </el-table-column>
          <el-table-column
            prop="no"
            label="客户编号"
            width="120">
          </el-table-column>
          <el-table-column
            prop="name"
            label="客户简称">
          </el-table-column>
        </el-table>
      </div>
      <div class="box2">
        <el-table
          height="495"
          :header-cell-style="{padding:0,height:'40px',background:'#f4f4f4'}"
          :cell-style="{padding:0,height:'36px'}"
          highlight-current-row
          @row-click="rowClick"
          ref="tableData"
          :data="tableData">
          <el-table-column
            prop="no"
            label="客户编号"
            width="120">
          </el-table-column>
          <el-table-column
            prop="name"
            label="客户简称">
          </el-table-column>
          <el-table-column
            prop="operator"
            label="操作员"
            width="120">
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { getClient } from '../../../../network/client'
export default {
  created(){
    //客户
    getClient().then(res => {
      console.log(res)
      if (res.data.code == 200) {
        let list = res.data.data
        list.forEach(e => {
          this.customerList.push({value:e.no,label:e.name})
          // this.clientData.push(e)
        })
      }
    })
  },
  data(){
    return {
      customerName: '',
      customerNo: '',
      clientData:[],
      tableData: [],
      customerList:[],
      details:[],
    }
  },
  methods: {
    //客户编号失去焦点
    customerNoBlur(){
      if (this.customerNo != '') {
        for (const i of this.customerList) {
          if (this.customerNo == i.value) {
            this.customerName = i.label
            return
          }
        }
        this.$alert('无此客户编号', '', {
          confirmButtonText: '确定'
        })
      }
    },

    close(){
      this.$emit('closeScreenCustomer')
    },
    //查询客户
    search(){
      this.clientData = []
      let obj = {no:this.customerNo}
      getClient(obj).then(res=>{
        // console.log(res.data)
        res.data.data.forEach(e=>{
          this.clientData.push(e)
        })
      })
    },
    preservationCN(){
      this.tableData = this.$refs.clientData.selection
      console.log(this.tableData)
      let q = []
      let w = []
      this.tableData.forEach(e=>{
        q.push(e.no)
        w.push(e.name)
      })
      let obj = [q,w]
      this.$emit("preservationCN",obj)
    },
    rowClick(e){
      this.details = [e]
    },
    Delete(){
      for(let a in this.tableData){
        for(let b of this.details){
          if(this.tableData[a] == b){
            this.tableData.splice(a,1)
          }
        }
      }
    },
    clean(){
      this.tableData.splice(this.$refs.clientData.selection,10000)
    },
  }
}
</script>

<style scoped>
  .screenCustomer .mask{
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    opacity: 0.3;
    z-index: 9;
  }
  .screenCustomer .screenCustomerContent{
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
    height: 650px;
    z-index: 99;
    background-color: white;
  }
  .screenCustomer .screenCustomerContent .screenCustomerTop{
    height: 40px;
    background-color: #f8f8f8;
  }
  .screenCustomer .screenCustomerContent .screenCustomerTop p{
    float: left;
    line-height: 40px;
    padding-left: 20px;
    font-weight: bold;
  }
  .screenCustomer .screenCustomerContent .screenCustomerTop i{
    float: right;
    line-height: 40px;
    padding: 0 16px;
  }
  .screenCustomer .screenCustomerBtn{
    background-color: #f8f8f8;
    height: 60px;
    padding: 15px 0 0 15px;
    margin:  15px 0;
  }

  .screenCustomer .box1, .screenCustomer .box2{
    display: inline-block;
    padding: 0 15px;
    width: 400px;
  }
  .screenCustomer .box1{
    border-right: 2px #f8f8f8 solid;
    box-sizing: border-box;
  }
  /* .screenCustomer .box2{ 
    width: 250px;
  } */
</style>

<style>
  .screenCustomer .el-input__inner{
    height: 30px;
  }
</style>